package com.project.finance.debit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.finance.common.mapper.TbDebitOrderMapper;
import com.project.finance.common.po.TbDebitOrder;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.debit.service.DebitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DebitServiceImpl implements DebitService {
    @Autowired
    private TbDebitOrderMapper tbDebitOrderMapper;


    @Override
    public List<TbDebitOrder> selectAll() {
        return tbDebitOrderMapper.selectAll();
    }

    @Override
    public int update(TbDebitOrder tbDebitOrder) {
        return tbDebitOrderMapper.updateByPrimaryKey(tbDebitOrder);
    }

    @Override
    public int delete(int debitorderid) {
        return tbDebitOrderMapper.deleteByPrimaryKey(debitorderid);
    }

    @Override
    public int insertOrder(TbDebitOrder tbDebitOrder) {
        return tbDebitOrderMapper.insert(tbDebitOrder);
    }

    @Override
    public List<TbDebitOrder> listSelect() {
        return tbDebitOrderMapper.listSelect();
    }

    @Override
    public ResultMsg listDebitOrderByPage(int pageSize, int pageNum) {
        ResultMsg resultMsg = new ResultMsg();

        PageHelper.startPage(pageNum,pageSize);

        List<TbDebitOrder> tbDebitOrders = tbDebitOrderMapper.listSelect();

        //获取结果集的分页信息
        PageInfo pageInfo =new PageInfo(tbDebitOrders);
        //获取总记录数
        long total = pageInfo.getTotal();
        resultMsg.setTatol(total);
        resultMsg.setData(tbDebitOrders);
        return resultMsg;
    }
}
